<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  var arr = function (nums, k, t) {
    const map = new Map();
    const len = nums.length;
    for (let i = 0; i < len; i++) {
      if (i > k) {//如果超过k则删除前端的一个
        map.delete(nums[i - k - 1]);
      }
      for (let [key, val] of map) {//for of 遍历key(nums[x]),val(x)
        if (Math.abs(nums[i] - key) <= t && Math.abs(i - val) <= k) {//判断两个条件是否符合
          return true
        }
      }
      map.set(nums[i], i);//遍历一个nums内容，给map增加一对,nums[i],i
    }
    return false
  };
  console.log(arr(nums = [1, 5, 9, 1, 5, 9], indexDiff = 2, valueDiff = 3));
</script>

</html>